<template>
  <!-- 点击新建的时候，显示这个组件 -->
  <div class="NewAt">
    <div class="mask"></div>
    <div class="newAt">
      <div class="vs-top">
        <p>新建资料（仓库调拨）</p>
        <i class="el-icon-close" @click="closeNewClerk"></i>
      </div>

      <div class="vs-info">
        <div class="vs-info-1">
          <p>调拨日期</p>
          <el-date-picker
            v-model="allotTime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
          <p>调入仓库</p>
          <div class="infoBox">
            <el-input
              v-model="foldWarehouse"
              @blur="foldWarehouseBlur"
              :disabled="sonFloortableData.length === 0 ? false : true"
            ></el-input>
            <el-select
              :disabled="sonFloortableData.length === 0 ? false : true"
              style="width: 100px"
              v-model="foldWarehouseName"
              @change="queryNo1"
            >
              <el-option
                v-for="item in foldWarehouseList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <p>调出仓库</p>
          <div class="infoBox">
            <el-input
              v-model="calloutWarehouse"
              @blur="calloutWarehouseBlur"
              :disabled="sonFloortableData.length === 0 ? false : true"
            ></el-input>
            <el-select
              v-model="calloutWarehouseName"
              @change="queryNo"
              :disabled="sonFloortableData.length === 0 ? false : true"
            >
              <el-option
                v-for="item in calloutWarehouseList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <!-- <p>款号</p>
          <el-input v-model="kindsNumber"></el-input> -->
        </div>
        <div class="vs-info-2">
          <!-- <p>品名</p>
          <el-input disabled v-model="commodityName"></el-input> -->
          <p>调拨序号</p>
          <el-input disabled v-model="diaobo_xuhaao"></el-input>
          <!-- <p style="margin-left: 10px">售价</p>
          <el-input disabled v-model="sellingPrice"></el-input> -->
          <p style="margin-left: 10px">备注</p>
          <el-input v-model="remark"></el-input>
        </div>

        <el-table
          border
          :data="codeData"
          id="codeTable"
          style="width: 100%; margin-bottom: 20px"
          max-height="148px"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
        >
          <el-table-column :label="header"> </el-table-column>
          <el-table-column prop="colorName" label="颜色"> </el-table-column>
          <!-- <el-table-column
            prop="colorNo"
            label="颜色編號">
          </el-table-column> -->

          <template v-for="col in sizeList">
            <el-table-column
              :key="col + Math.random()"
              :prop="col"
              :label="col"
            >
              <template slot-scope="scope">
                <!-- <el-form :v-model="scope.row"> -->
                <!-- <el-form-item> -->
                <!-- <el-input v-model="scope.row[col]" @blur="handleClick(scope.$index,scope.row[col])" ></el-input>
                  <span>{{scope.row[col]}}</span> -->
                <!-- </el-form-item> -->
                <!-- </el-form> -->

                <el-input
                  size="small"
                  class="innerInp"
                  v-model="scope.row[col]"
                  @blur="
                    handleClick($event, {
                      index: scope.$index,
                      key: col,
                      result: scope.row[col]
                    })
                  "
                  @keyup.enter.native="inpEnter"
                >
                </el-input>
              </template>
            </el-table-column>
          </template>
        </el-table>
        <!-- 根据后端要求，直接注释rfid -->
        <!-- <div class="barcode">
          <p>条码扫描</p>
          <el-switch
            v-model="isBarcode"
            :disabled="isDis"
            active-color="#409EFF"
            inactive-color="#C0C4CC"
          >
          </el-switch>
          <div style="display: flex">
            <p>条码选择</p>
            <el-radio :disabled="!isBarcode" v-model="radio" label="1"
              >货号码</el-radio
            >
            <el-radio :disabled="!isBarcode" v-model="radio" label="2"
              >ID码</el-radio
            >
            <i
              class="el-icon-question"
              style="color: #017fff; margin: 3px 6px 0 0"
            ></i>
            <p>按F7设置扫码数量</p>
          </div>
        </div> -->

        <div class="enterBarcode">
          <el-input
            v-model="searchValue"
            id="input"
            placeholder="扫描/输入货号或款号，输完按回车"
            @keyup.enter.native="barcodeEnter1($event)"
          >
          </el-input>
          <p style="margin: 15px 0 0 5px">合计：{{ howMany }}</p>
        </div>

        <el-table
          height="380px"
          :data="sonFloortableData"
          style="width: 100%"
          :header-cell-style="{
            background: '#f4f4f4',
            padding: 0,
            height: '40px'
          }"
          :cell-style="{ padding: 0, height: '36px' }"
        >
          <el-table-column
            prop="kindsNumber"
            show-overflow-tooltip
            label="货号"
          >
          </el-table-column>
          <el-table-column prop="colorName" label="颜色"> </el-table-column>
          <el-table-column prop="sizeNo" label="尺码编号"> </el-table-column>
          <el-table-column prop="sum" label="数量"> </el-table-column>
          <!-- <el-table-column prop="onePrice" label="单价"> </el-table-column> -->
          <el-table-column prop="sellingPrice" label="售价"> </el-table-column>
          <el-table-column prop="commodityName" label="品名"> </el-table-column>
        </el-table>
      </div>

      <div class="vs-btn">
        <el-button @click="closeNewClerk">取消</el-button>
        <!-- 这个原来是保存的 ，修改的东西不多，只是将原来继续录入的代码，复制一点到保存，并且在保存中更改了一个字段参数-->
        <el-button type="primary" @click="savenewAt">继续录入</el-button>
        <!-- <el-button type="primary" @click="keepGoing">继续录入</el-button> -->
      </div>

      <!-- F7弹出框 -->
      <div class="popup" :style="{ display: showPopup }">
        <div class="popup_t">
          <p>输入扫描数量</p>
          <i @click="closePopup" class="el-icon-close"></i>
        </div>
        <div class="popup_c">
          <p>请输入扫描数量</p>
          <p>如果不输入则扫描数量为1</p>
          <el-input
            v-model="scanNum"
            style="margin-top: 10px"
            @keyup.enter="determine"
          ></el-input>
          <!-- <input type="text" 
            class="popup_button" 
            v-model="scanNum"
            @keyup.enter="determine"> -->
        </div>
        <div class="popup_b">
          <el-button @click="closePopup">取消</el-button>
          <el-button type="primary" @click="determine">确定</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { AddWarehouse } from '../../../../network/manufacturer.js'
/*  */
import { getWarehouse } from '../../../../network/warehouse'
import {
  searchKindsNumber,
  getScanning,
  getBarCode,
  factoryInputScanner
} from '../../../../network/manufacturer'
import today from '../../../../components/mixins/today'
import { getNumber } from '../../../../network/customerOutTotal'
import { getKindsNumberList } from '../../../../network/artNo'
export default {
  name: 'NewAT',
  mixins: [today],
  props: {
    detailInfo: {
      type: Object,
      default: {}
    },
    seq: {
      type: String,
      default: ''
    },
    newbuild: {
      type: String,
      default: ''
    },
    diaobo_xuhaao: {
      type: String,
      default: ''
    },
    // 底部表格数组，由父组件传递过来，这样是为了避免过多的修改原来代码
    sonFloortableData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  created() {
    // 清空备注的数据
    this.remark = ''
    // 清空调拨序号
    // this.allotSequence = ''
    this.allotTime = this.getNowTime()
    console.log('111111')
    console.log(this.getNowTime())
    //仓库
    getWarehouse().then((res) => {
      console.log(res.data.data)
      res.data.data.forEach((e) => {
        this.foldWarehouseList.push({
          label: e.name,
          value: e.name,
          value1: e.no,
          Main: e.isMainWarehouse
        })
        this.calloutWarehouseList.push({
          label: e.name,
          value: e.name,
          value1: e.no,
          Main: e.isMainWarehouse
        })
      })
      for (let a of res.data.data) {
        if (a.isMainWarehouse == 1) {
          this.foldWarehouse = a.no //主仓库
          this.foldWarehouseName = a.name
        }
      }
    })
  },
  data() {
    return {
      /* 新增的map集合 */
      mapList: {},
      howMany: '',
      searchValue: '',
      AAa: [],
      isDis: false,
      ak: [],

      showPopup: 'none',
      isEdit: true,
      // allotTime: [],
      allotTime: '',
      foldWarehouse: '',
      foldWarehouseName: '',
      foldWarehouseList: [],
      calloutWarehouse: '',
      calloutWarehouseName: '',
      calloutWarehouseList: [],
      // kindsNumber:'',
      commodityName: '',
      // allotSequence: '',
      sellingPrice: '',
      remark: '',
      codeData: [],
      cols: ['7', '9', '1', '3', '5', '7', 'F'],

      header: '',
      isBarcode: false,
      radio: '1',
      barcodeData: [],
      scanNum: 1,
      Rid: [],
      cols1: [],
      sizeList: [],
      XHList: [],
      XHList1: [],
      barcodeData1: []
    }
  },

  methods: {
    handleClick(e, { index, key, result }) {
      // let r = /^\+?[1-9][0-9]*$/
      let r = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/
      if (result != 0) {
        result = result.replace(/\b(0+)/gi, '')
      }
      if (!r.test(result) && result) {
        this.$alert('数量请输入整数', '', {
          confirmButtonText: '确定'
        })
        this.codeData[index][key] = 0
        return
      }
      this.codeData[index][key] = result
    },
    inpEnter(e) {
      e.target.parentNode.parentNode.parentNode.classList.remove('activeCell')
    },
    // 调入仓库失去焦点
    foldWarehouseBlur() {
      if (this.foldWarehouse != '') {
        for (const i of this.foldWarehouseList) {
          if (this.foldWarehouse == i.value1) {
            this.foldWarehouseName = i.label
            return
          }
        }
        this.$message({
          type: 'warning',
          offset: 400,
          message: '无此仓库编号'
        })
        this.foldWarehouse = ''
        this.foldWarehouseName = ''
      } else {
        this.foldWarehouseName = ''
      }
    },
    //调出仓 编号
    queryNo() {
      for (let s of this.calloutWarehouseList) {
        if (s.value == this.calloutWarehouseName) {
          this.calloutWarehouse = s.value1
          if (this.calloutWarehouse == this.foldWarehouse) {
            this.$message({
              type: 'warning',
              offset: 400,
              message: '调入仓库与调出仓库不能为同一个'
            })
            this.calloutWarehouse = ''
            this.calloutWarehouseName = ''
          }
        }
      }
    },
    queryNo1() {
      for (let s of this.foldWarehouseList) {
        if (s.value == this.foldWarehouseName) {
          this.foldWarehouse = s.value1
          if (this.foldWarehouse == this.calloutWarehouse) {
            this.$message({
              type: 'warning',
              offset: 400,
              message: '调入仓库与调出仓库不能为同一个'
            })
            // this.foldWarehouse = ''
            this.foldWarehouseName = ''
          }
        }
      }
    },
    //调出仓库编号失去焦点
    calloutWarehouseBlur() {
      if (this.calloutWarehouse != '') {
        for (const i of this.calloutWarehouseList) {
          if (this.calloutWarehouse == i.value1) {
            this.calloutWarehouseName = i.label
            return
          }
        }
        this.$message({
          type: 'warning',
          offset: 400,
          message: '无此仓库编号'
        })
        this.calloutWarehouse = ''
        this.calloutWarehouseName = ''
      } else {
        this.calloutWarehouseName = ''
      }
    },
    determine() {
      this.scanNum = this.scanNum
      this.showPopup = 'none'
      this.$message({
        type: 'success',
        offset: 400,
        message: '数量设置成功'
      })
    },
    //保存
    savenewAt() {
      if (
        this.allotTime == '' ||
        this.foldWarehouse == '' ||
        this.calloutWarehouse == ''
      ) {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '调拨日期，仓库编号不能为空'
        })
        return
      }
      /* 
          拷贝继续录入代码，动态拼接款号
      */
      // 输入 this.isBarcode永远都是false,默认是false，并且被注释掉
      let knList = []
      this.codeData.forEach((e) => {
        let c = e.colorNo
        this.sizeList.forEach((f) => {
          if (this.manufacturerBarCode.styleColorSize) {
            // 型尺色

            if (this.manufacturerBarCode.styleColor) {
              // 款号与尺码之间有 -

              if (this.manufacturerBarCode.colorSize) {
                // 色号与尺码之间有 -
                knList.push({
                  kindsNumber: `${this.header}-${f}-${c}`,
                  sum: e[f]
                })
              } else {
                // 色号与尺码之间没有 -
                knList.push({
                  kindsNumber: `${this.header}-${f}${c}`,
                  sum: e[f]
                })
              }
            } else {
              // 款号与尺码之间没有 -
              if (this.manufacturerBarCode.colorSize) {
                // 色号与尺码之间有 -
                knList.push({
                  kindsNumber: `${this.header}${f}-${c}`,
                  sum: e[f]
                })
              } else {
                // 色号与尺码之间没有 -
                knList.push({
                  kindsNumber: `${this.header}${f}${c}`,
                  sum: e[f]
                })
              }
            }
          } else {
            // 型色尺

            if (this.manufacturerBarCode.styleColor) {
              // 款号与颜色之间有 -

              if (this.manufacturerBarCode.colorSize) {
                // 色号与尺码之间有 -
                knList.push({
                  kindsNumber: `${this.header}-${c}-${f}`,
                  sum: e[f]
                })
              } else {
                // 色号与尺码之间没有 -
                knList.push({
                  kindsNumber: `${this.header}-${c}${f}`,
                  sum: e[f]
                })
              }
            } else {
              // 款号与颜色之间没有 -

              if (this.manufacturerBarCode.colorSize) {
                // 色号与尺码之间有 -
                knList.push({
                  kindsNumber: `${this.header}${c}-${f}`,
                  sum: e[f]
                })
              } else {
                // 色号与尺码之间没有 -
                knList.push({
                  kindsNumber: `${this.header}${c}${f}`,
                  sum: e[f]
                })
              }
            }
          }
        })
      })

      // console.log('这个是表格中合并的色号', knList)
      this.XHList1 = knList
      var kindList = {}
      knList.forEach((e) => {
        if (e.sum != '') {
          kindList[e.kindsNumber] = e.sum
        }
      })
      /* fei */
      // this.mapList = kindList
      console.log('这个是要传给后端的map集合，其实就是一个对象', kindList)
      /*到这里结束---------------------------------------- */

      /*
      ------------------------------------------start------------------------
      var ie = []
      var io = []
      var ip = []
      var iu = {}
      var il
      // barcodeData这个是底部表格的数据 kindList
      for (var t of this.barcodeData) {
        // if(this.isBarcode && this.radio == '1'){
        //   il = 1
        // }
        // else if(this.isBarcode && this.radio == '2'){
        //   // ie.push(t.rfID)
        //   // console.log(ip)
        //   il = 2
        // };
        ie.push(t.kindsNumber)
        console.log(ie)
        io.push(t.sum)
        for (var g in ie) {
          for (var h in io) {
            if ((g = h)) {
              iu[ie[g]] = io[h] //属性值作为属性名
            }
          }
        }
      } 
      ------------------------------------------原来就在的代码（end）------------------------
      */
      /* 这里的遍历，主要是将值变成数字 */
      for (let key in kindList) {
        kindList[key] = Number(kindList[key])
      }
      console.log('遍历过后的kindList', kindList)
      let params = {
        allotTime: this.allotTime,
        foldWarehouse: this.foldWarehouse,
        calloutWarehouse: this.calloutWarehouse,
        commodityName: this.commodityName,
        // 调拨序号
        allotSequence: this.diaobo_xuhaao,
        sellingPrice: this.sellingPrice,
        remark: this.remark,
        // kindsNumberMap: iu,
        kindsNumberNumberMap: kindList,
        rfidList: this.Rid,
        dataSource: this.radio == '1' ? 1 : 0
        /* 新增 */
        // kindsNumberNumberMap: this.mapList
      }
      console.log('params', params)
      // 点击保存的时候，触发这个方法
      this.$emit('savenewAt', params)
      // this.Rid = []
      /* 原来是采取父组件监听的形式，现在直接在子组件传给父组件 */

      // console.log(JSON.stringify(this.barcodeData).replace(/^\[|\]$/g,''))//去掉最外层中括号
      // AddWarehouse(JSON.stringify(this.barcodeData).replace(/^\[|\]$/g,'')).then(res=>{

      this.barcodeData = []
      this.barcodeData1 = []
      // 不能清空 调入仓库 和 调出仓库
      // this.calloutWarehouse = ''
      // this.calloutWarehouseName = ''

      this.searchValue = ''
      this.isDis = false
      this.howMany = ''
      // this.$emit("savenewAt")
      /* 点击继续录入之后，要清空 */
      this.codeData = []
      console.log('okoko')
    },
    /*  */
    cellClick() {},
    //继续录入
    keepGoing() {
      console.log('----------------------------------------------------')
      // 要打开这个注释才行
      if (
        this.allotTime == '' ||
        this.foldWarehouse == '' ||
        this.calloutWarehouse == ''
      ) {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '调拨日期，仓库编号不能为空'
        })
        return
      }
      //   }
      //   var iu = {}
      //   this.barcodeData.forEach(e=>{
      //     iu[e.kindsNumber] = e.sum
      //   })

      //   let params = {
      //     allotTime:this.allotTime,
      //     foldWarehouse:this.foldWarehouse,
      //     calloutWarehouse:this.calloutWarehouse,
      //     commodityName:this.commodityName,
      //     allotSequence:this.allotSequence,
      //     sellingPrice:this.sellingPrice,
      //     remark:this.remark,
      //     kindsNumberMap:iu,
      //     rfidList:this.Rid,
      //     dataSource:this.radio == '1' ? 1 : 0
      //   }
      //   console.log(params)
      // this.$emit("keepSave",params)
      // this.Rid = []
      // this.searchValue = ''
      // this.barcodeData = []
      if (!this.isBarcode) {
        // 这个isBarcode 默认是false,而且那个注释掉了，那么就是逻辑永远都是走这里
        console.log('----------zhek-----------------------------------------1')
        // 点击继续录入的时候，只走这里
        this.continueInput()
        this.codeData = []
      } else {
        this.barcodeEnter1()
      }
    },
    /* 这个是输入最后input的时候输入的 */
    continueInput() {
      if (
        this.allotTime == '' ||
        this.foldWarehouse == '' ||
        this.calloutWarehouse == ''
      ) {
        this.$message({
          type: 'warning',
          offset: 400,
          message: '调拨日期，仓库编号不能为空'
        })
        return
      }

      let kindsNumberNumMap = {}
      if (this.isBarcode) {
        // 扫描
        if (this.radio == 1) {
          // 扫描货号码
          kindsNumberNumMap[this.searchValue] = this.scanNum
        } else if (this.radio == 2) {
          console.log('id')
          // 扫描ID码
          searchKindsNumber({
            // 条码与货号是否一致
            isSame: false,
            // 是否开启条码扫描
            isScanner: true,
            searchValue: this.searchValue
          }).then((res) => {
            // console.log('这个是', res)
            kindsNumberNumMap[res.data.data[0].kindsNumber] = this.scanNum
          })
        }
      } else {
        // 输入 this.isBarcode永远都是false,默认是false，并且被注释掉
        let knList = []
        this.codeData.forEach((e) => {
          let c = e.colorNo
          this.sizeList.forEach((f) => {
            if (this.manufacturerBarCode.styleColorSize) {
              // 型尺色

              if (this.manufacturerBarCode.styleColor) {
                // 款号与尺码之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${f}${c}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与尺码之间没有 -
                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}-${c}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${f}${c}`,
                    sum: e[f]
                  })
                }
              }
            } else {
              // 型色尺

              if (this.manufacturerBarCode.styleColor) {
                // 款号与颜色之间有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}-${c}${f}`,
                    sum: e[f]
                  })
                }
              } else {
                // 款号与颜色之间没有 -

                if (this.manufacturerBarCode.colorSize) {
                  // 色号与尺码之间有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}-${f}`,
                    sum: e[f]
                  })
                } else {
                  // 色号与尺码之间没有 -
                  knList.push({
                    kindsNumber: `${this.header}${c}${f}`,
                    sum: e[f]
                  })
                }
              }
            }
          })
        })

        // console.log('这个是表格中合并的色号', knList)
        this.XHList1 = knList
        var kindList = {}
        knList.forEach((e) => {
          if (e.sum != '') {
            kindList[e.kindsNumber] = e.sum
          }
        })
        /* fei */
        // this.mapList = kindList
        console.log('这个是要传给后端的map集合，其实就是一个对象', kindList)
      }
      // /*  */
      // var ie = []
      // var io = []
      // var iu = {}
      // for (var t of this.barcodeData) {
      //   console.log(ie)
      //   io.push(t.sum)
      //   for (var g in ie) {
      //     for (var h in io) {
      //       if ((g = h)) {
      //         iu[ie[g]] = io[h] //属性值作为属性名
      //       }
      //     }
      //   }
      // }

      // let params = {
      //   allotTime: this.allotTime,
      //   foldWarehouse: this.foldWarehouse,
      //   calloutWarehouse: this.calloutWarehouse,
      //   commodityName: this.commodityName,
      //   // 调拨序号
      //   allotSequence: this.allotSequence,
      //   sellingPrice: this.sellingPrice,
      //   remark: this.remark,
      //   kindsNumberMap: iu,
      //   rfidList: this.Rid,
      //   dataSource: this.radio == '1' ? 1 : 0,
      //   /* 新增 */
      //   kindsNumberNumberMap: this.mapList
      // }
      // console.log('params', params)
      // // 点击保存的时候请求的api
      // AddWarehouse(JSON.stringify(params)).then((res) => {
      //   console.log('点击保存拿到的返回数据', res)
      //   if (res.data.code == 200) {
      //     this.$message({
      //       type: 'success',
      //       message: '保存成功'
      //     })
      //     // 暂时不知道
      //     this.DList = res.data.data
      //     // 这个是现在在表格中的数据
      //     this.tab1Data = res.data.data.insertList
      //     // 款号输入框右边的合计
      //     this.howMany = this.tab1Data.reduce((prev, next) => {
      //       //tab1Data数组里所有number的和
      //       return prev + next.number
      //     }, 0)
      //     for (let y of this.tab1Data) {
      //       // 遍历为input赋值
      //       // 调拨日期
      //       this.allotTime = y.allotTime
      //       // foldWarehouse（调入仓库）
      //       this.foldWarehouse = y.foldWarehouse
      //       // 调出仓库
      //       this.calloutWarehouse = y.calloutWarehouse
      //       //调拨序号
      //       this.allotSequence = y.allotSequence
      //       this.remark = y.remark
      //       this.rwareHouse = y.foldWarehouse
      //       this.cwareHouse = y.calloutWarehouse
      //     }

      //     if (res.data.data.validRfidList != undefined) {
      //       res.data.data.validRfidList.forEach((e) => {
      //         this.tabData.push(e)
      //       })
      //     }

      //     if (res.data.data.errorValidRfidList != undefined) {
      //       this.exportRaw(
      //         String(res.data.data.errorRfidList),
      //         '库存不足Rfid .txt'
      //       )
      //     }
      //   } else {
      //     this.$message.error({
      //       message: '保存失败'
      //     })
      //   }
      // })
      // ------------------------------------------------------
      /*  */
      //判断库存够不够
      let kindsNumberNumberMap = kindList
      let obj3 = {
        companyNo: this.calloutWarehouse,
        kindsNumberNumberMap
      }
      console.log('obj3', obj3)
      getNumber(JSON.stringify(obj3)).then((res) => {
        // 这个是点击继续录入成功
        console.log('res.data', res)
        if (res.data.code === 200) {
          // console.log(1000000000)
          // this.savenewAt()
        }
        if (res.data.code == 202) {
          this.$message.error({
            message: '查无此对象'
          })
          return
        }
        for (var g in this.XHList1) {
          for (let k in res.data.data) {
            if (
              this.XHList1[g].kindsNumber == res.data.data[k] ||
              this.XHList1[g].sum == ''
            ) {
              this.$message.error({
                message: `${res.data.data}'货号库存不够'`
              })
              this.XHList1.splice(g, 1)
              console.log(this.XHList1)
            }
          }
        }
        for (let a in this.XHList1) {
          for (let b in this.XHList) {
            if (
              this.XHList1[a].kindsNumber == this.XHList[b].kindsNumber &&
              this.XHList1[a].sum != ''
            ) {
              this.XHList[b]['sum'] = this.XHList1[a].sum
              this.XHList[b]['onePrice'] =
                Number(this.XHList[b].sum) * Number(this.XHList[b].sellingPrice)
              this.XHList[b]['dataSource'] = 1
              this.barcodeData1.push(this.XHList[b])
              console.log(this.barcodeData1)
            }
            this.aka()
          }
        }
        this.howMany = this.barcodeData.reduce((prev, next) => {
          return prev + next.sum
        }, 0)
      })
    },

    aka() {
      //数组对象里 kindsNumber相同  数量相加 合并
      var tmp = {}
      for (let u in this.barcodeData1) {
        var key = this.barcodeData1[u].kindsNumber
        if (tmp[key]) {
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].sum += Number(this.barcodeData1[u].sum)

          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber =
            this.barcodeData1[u].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber =
            this.barcodeData1[u].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition =
            this.barcodeData1[u].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        } else {
          tmp[key] = {}
          tmp[key].kindsNumber = this.barcodeData1[u].kindsNumber
          tmp[key].sum = Number(this.barcodeData1[u].sum)
          tmp[key].waveBand = this.barcodeData1[u].waveBand
          tmp[key].vipPrice = this.barcodeData1[u].vipPrice
          tmp[key].supplier = this.barcodeData1[u].supplier
          tmp[key].styleNumber = this.barcodeData1[u].styleNumber
          tmp[key].status = this.barcodeData1[u].status
          tmp[key].statistics = this.barcodeData1[u].statistics
          tmp[key].splitNumber = this.barcodeData1[u].splitNumber
          tmp[key].softwareCustomerId = this.barcodeData1[u].softwareCustomerId
          tmp[key].sizeNo = this.barcodeData1[u].sizeNo
          tmp[key].sizeKind = this.barcodeData1[u].sizeKind
          tmp[key].size = this.barcodeData1[u].size
          tmp[key].sellingPriceTwo = this.barcodeData1[u].sellingPriceTwo
          tmp[key].sellingPriceThree = this.barcodeData1[u].sellingPriceThree
          tmp[key].sellingPriceOne = this.barcodeData1[u].sellingPriceOne
          tmp[key].sellingPriceFour = this.barcodeData1[u].sellingPriceFour
          tmp[key].sellingPrice = this.barcodeData1[u].sellingPrice
          tmp[key].relevanceSize = this.barcodeData1[u].relevanceSize
          tmp[key].quarter = this.barcodeData1[u].quarter
          tmp[key].originalManufacturerKindsNumber =
            this.barcodeData1[u].originalManufacturerKindsNumber
          tmp[key].originalKindsNumber =
            this.barcodeData1[u].originalKindsNumber
          tmp[key].onePrice = this.barcodeData1[u].onePrice
          tmp[key].newSize = this.barcodeData1[u].newSize
          tmp[key].newKindsNumber = this.barcodeData1[u].newKindsNumber
          tmp[key].mnemonicCode = this.barcodeData1[u].mnemonicCode
          tmp[key].matchStyle = this.barcodeData1[u].matchStyle
          tmp[key].manufacturerType = this.barcodeData1[u].manufacturerType
          tmp[key].manufacturerPrice = this.barcodeData1[u].manufacturerPrice
          tmp[key].kindSort = this.barcodeData1[u].kindSort
          tmp[key].image = this.barcodeData1[u].image
          tmp[key].id = this.barcodeData1[u].id
          tmp[key].generalizePrice = this.barcodeData1[u].generalizePrice
          tmp[key].discount = this.barcodeData1[u].discount
          tmp[key].differentiateCondition =
            this.barcodeData1[u].differentiateCondition
          tmp[key].costTwo = this.barcodeData1[u].costTwo
          tmp[key].costOne = this.barcodeData1[u].costOne
          tmp[key].commodityType = this.barcodeData1[u].commodityType
          tmp[key].commodityName = this.barcodeData1[u].commodityName
          tmp[key].colorNo = this.barcodeData1[u].colorNo
          tmp[key].colorName = this.barcodeData1[u].colorName
          tmp[key].brandedName = this.barcodeData1[u].brandedName
          tmp[key].brandedCompany = this.barcodeData1[u].brandedCompany
          tmp[key].accessoryName = this.barcodeData1[u].accessoryName
        }
      }
      // 点击继续录入之后，这个表格是前端拼接
      this.barcodeData = []
      for (let k in tmp) {
        this.barcodeData.push(tmp[k])
      }
      // console.log(this.barcodeData)
    },

    barcodeEnter1(e) {
      console.log(e)
      if (this.searchValue) {
        //关闭条码扫描
        if (!this.isBarcode) {
          // 手输款号
          getKindsNumberList({ kindsNumberStr: this.searchValue }).then(
            (res) => {
              // console.log('第一个', res)
              this.XHList = res.data.data.data
              console.log(this.XHList)
              if (res.data.data.data.length) {
                this.header = res.data.data.data[0].styleNumber
                this.$emit('inpNumChange')
                // 品牌公司查条码规律详情
                getBarCode({
                  company: res.data.data.data[0].brandedCompany
                }).then((res) => {
                  // console.log('第二个', res)
                  this.manufacturerBarCode = res.data.data[0]
                })
                // console.log(this.manufacturerBarCode)
                // 输入款号显示中间表和尺码信息   ZZZ-AAS
                res.data.data.data.sort((a, b) => {
                  return a.relevanceSize.localeCompare(b.relevanceSize)
                })
                let tmp = res.data.data.data
                this.tmpBarcodeData = tmp
                // console.log(tmp)

                // 中间表  尺码表头
                this.sizeList = [tmp[0].size]
                let isExistSize = 0
                for (const i of tmp) {
                  for (const j of this.sizeList) {
                    if (j == i.size) {
                      isExistSize = 0
                      break
                    }
                    isExistSize = 1
                  }
                  if (isExistSize) {
                    this.sizeList.push(i.size)
                    // console.log(this.sizeList)
                  }
                }

                // 中间表
                let tmpCodeData = [
                  { colorNo: tmp[0].colorNo, colorName: tmp[0].colorName }
                ]
                let isExistColor = 0
                for (const i of tmp) {
                  for (const j of tmpCodeData) {
                    if (j.colorName == i.colorName) {
                      isExistColor = 0
                      break
                    }
                    isExistColor = 1
                  }
                  if (isExistColor) {
                    tmpCodeData.push({
                      colorNo: i.colorNo,
                      colorName: i.colorName
                    })
                  }
                }
                tmpCodeData.forEach((e) => {
                  this.sizeList.forEach((f) => {
                    e[f] = ''
                  })
                })
                this.codeData = tmpCodeData
                let codeTable = document.getElementById('codeTable')
                let inputs = codeTable.getElementsByTagName('input')
                // console.log(inputs)
                let int = setInterval(() => {
                  clearInterval(int)
                  inputs[0].focus()
                  inputs[inputs.length - 1].onkeyup = (e) => {
                    if (window.event.keyCode == 13) {
                      this.continueInput()
                      inputs[inputs.length - 1].onkeyup = () => {}
                      this.codeData = []
                    }
                  }
                }, 100)
              } else {
                this.$message('此货号/款号无数据')
                this.$refs.barcodeInput.focus()
              }
            }
          )
        } else {
          //开条码扫描
          if (this.allotTime == '' || this.calloutWarehouse == '') {
            this.$message({
              type: 'error',
              message: '调拨日期，仓库编号不能为空'
            })
            return
          }

          if (this.isBarcode && this.radio == '1') {
            //扫货号码
            let kindsNumberNumberMap = {}
            kindsNumberNumberMap[this.searchValue] = Number(this.scanNum)
            let obj3 = {
              companyNo: this.calloutWarehouse,
              kindsNumberNumberMap
            }
            console.log(obj3)
            //判断库存够不够
            getNumber(JSON.stringify(obj3)).then((res) => {
              console.log(res.data)
              if (res.data.code == 202) {
                this.$message.error({
                  message: '查无此对象'
                })
                return
              }
              if (res.data.data == this.searchValue) {
                this.$message.error({
                  message: '此货号库存不够'
                })
                return
              } else {
                var tf
                if (this.isBarcode == false) {
                  tf = true
                }
                if (this.isBarcode && this.radio == '1') {
                  tf = true
                } else if (this.isBarcode && this.radio == '2') {
                  tf = false
                }
                let obj2 = {
                  isKindsNumber: true,
                  searchValue: this.searchValue
                }
                console.log(obj2)

                getScanning(obj2).then((res) => {
                  this.isDis = true
                  if (res.data.data == null) {
                    this.$message({
                      type: 'error',
                      message: '该货号/ID码没有数据'
                    })
                    return
                  } else if (this.isBarcode && this.radio == '2') {
                    // var sss = {showCode:this.searchValue}
                    this.Rid.push(this.searchValue)
                  }
                  this.AAa = res.data.data
                  for (let w in this.AAa) {
                    this.AAa[w]['sum'] = this.scanNum
                    this.AAa[w]['onePrice'] =
                      this.AAa[w].sellingPrice * (this.AAa[w].discount / 10)
                    this.AAa[w]['allotTime'] = this.allotTime
                    this.AAa[w]['sequence'] = this.sequence
                    this.AAa[w]['calloutWarehouse'] = this.calloutWarehouse
                    this.AAa[w]['dataSource'] = tf == true ? 1 : 0
                    // this.AAa[w]["kindsNumberMap"] = []
                    // this.AAa[w]["rfidList"] = []
                    if (tf == false) {
                      this.AAa[w]['rfID'] = this.searchValue
                    } else {
                      this.AAa[w]['kNumber'] = this.searchValue
                    }
                  }

                  if (this.barcodeData == '') {
                    this.barcodeData = this.AAa
                  } else {
                    this.merge(this.barcodeData, this.AAa)
                    // this.AAa为一条数据 两组数据比较 this.barcodeData数组对象里的kindsNumber与this.AAa数组对象里的kindsNumber一样 sum 就相加 else 就push进this.barcodeData
                  }

                  this.howMany = this.barcodeData.reduce((prev, next) => {
                    return prev + next.sum
                  }, 0)
                  this.searchValue = ''
                  document.getElementById('input').focus()
                  console.log(this.barcodeData)
                })
              }
            })
          } else if (this.isBarcode && this.radio == '2') {
            //扫RFID码
            let existence = this.Rid.indexOf(this.searchValue) //如果有就返回下标 没有返回-1
            if (existence != -1) {
              this.$message.warning({ message: '该ID码已扫描', offset: 400 })
              return
            }

            let obj1 = {
              rfidValue: this.searchValue
            }
            factoryInputScanner(obj1).then((res) => {
              console.log(res)
              if (res.data.data == null) {
                this.$message.error('无此RFID数据')
                return
              } else if (res.data.code == 200 && res.data.data != null) {
                this.Rid.push(this.searchValue)
                this.AAa = [res.data.data]
                for (let g in this.AAa) {
                  this.AAa[g]['sum'] = this.scanNum
                  this.AAa[g]['onePrice'] =
                    this.AAa[g].sellingPrice * (this.AAa[g].discount / 10)
                  this.AAa[g]['allotTime'] = this.allotTime
                  this.AAa[g]['sequence'] = this.sequence
                  this.AAa[g]['calloutWarehouse'] = this.calloutWarehouse
                  this.AAa[g]['dataSource'] = 0
                  this.AAa[g]['rfID'] = this.searchValue
                }

                if (this.barcodeData == '') {
                  this.barcodeData = this.AAa
                } else {
                  this.merge(this.barcodeData, this.AAa)
                  // this.AAa为一条数据 两组数据比较 this.barcodeData数组对象里的kindsNumber与this.AAa数组对象里的kindsNumber一样 sum 就相加 else 就push进this.barcodeData
                }

                this.howMany = this.barcodeData.reduce((prev, next) => {
                  return prev + next.sum
                }, 0)
                this.searchValue = ''
                document.getElementById('input').focus()
                console.log(this.barcodeData)
              }
            })
          }
        }
      }
    },
    merge(target, source) {
      const targetIds = target.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      const sourceIds = source.reduce(
        (res, v) => res.add(v.kindsNumber),
        new Set()
      )
      target.forEach((v) => sourceIds.has(v.kindsNumber) && v.sum++)
      return target.push(...source.filter((v) => !targetIds.has(v.kindsNumber)))
    },

    closePopup() {
      this.barcodeData = []
      this.showPopup = 'none'
    },
    closeNewClerk() {
      /* fei添加：点击新建的时候能初始化 */
      // this.allotSequence = ''
      this.codeData = []
      this.header = ''
      this.sizeList = []
      this.barcodeData1 = []
      this.barcodeData = []
      this.remark = ''
      this.isDis = false
      this.searchValue = ''
      this.scanNum = 1
      this.Rid = []
      this.howMany = ''
      this.$emit('closeNewClerk')
    }
  },
  mounted() {
    let _this = this
    document.onkeydown = function (event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      if (e && e.keyCode == 118) {
        // 按 F7
        if (_this.showPopup == 'none') {
          _this.showPopup = 'block'
        } else {
          _this.showPopup = 'none'
        }
      }
    }
  },
  watch: {
    searchValue(a, b) {
      if (a) {
        this.searchValue = a.toUpperCase().trim()
      }
    },
    seq(a, b) {
      console.log(this.seq)
      // this.allotSequence = this.seq
    },
    detailInfo(a, b) {
      this.allotTime = a.allotTime
      /* fei 因为点击新建的时候，没有初始化*/
      // this.allotSequence = a.allotSequence
      this.foldWarehouse = a.foldWarehouse
      /* fei 因为点击新建的时候，没有初始化*/
      this.calloutWarehouse = a.calloutWarehouse
      this.calloutWarehouseName = a.calloutWarehouseName
      // this.kindsNumber = a.kindsNumber
      this.remark = a.remark
    }
  }
}
</script>

<style scoped>
/* 新建资料 */
.mask {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.3;
  z-index: 9;
}
.newAt {
  position: fixed;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: 1070px;
  max-height: 90%;
  z-index: 99;
  background-color: white;
  overflow: auto;
}
.newAt .vs-top {
  height: 40px;
  background-color: #f8f8f8;
}
.newAt .vs-top p {
  float: left;
  line-height: 40px;
  padding-left: 20px;
  font-weight: 700;
}
.newAt .vs-top i {
  float: right;
  line-height: 40px;
  padding: 0 16px;
}

.newAt input {
  height: 30px;
  border: solid 1px #dcdfe6;
  border-radius: 5px;
  margin-left: 10px;
}
.newAt input:focus {
  outline: none;
  border: solid 1px #409eff;
}
.newAt .vs-info-2 .inp-2 {
  margin-right: 15px;
}
/* .vs-info-1,.vs-info-2{
    
  } */
.vs-info {
  padding: 0 15px;
  padding-bottom: 10px;
  /* border-bottom: solid #f2f2f2 2px; */
}
.vs-info-1 p,
.vs-info-2 p {
  display: inline-block;
  width: 75px;
  text-align: right;
  margin-right: 15px;
}
/* .vs-info-1 p:nth-child(3){
    margin-left: 10px;
  }
  .newAt .vs-info-1 .inp-2{
    margin-right: 43px;
  } */
.vs-info .vs-info-2 {
  margin-bottom: 15px;
}
.vs-info .barcode p {
  display: inline;
  margin-right: 15px;
}
.vs-info .barcode div {
  margin-top: 15px;
}

.colorBox,
.infoBox {
  display: inline;
}

.enterBarcode {
  display: flex;
  height: 60px;
  background-color: #f2f2f2;
  margin: 15px 0;
}

.vs-btn {
  float: right;
  margin: 0 15px 15px;
}

.popup {
  width: 400px;
  height: 200px;
  border: 2px solid #f4f4f4;
  box-shadow: 0 2px 2px 2px #dbdbdb;
  z-index: 999;
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -100px 0 0 -200px;
  background: white;
  display: block;
}
.popup_t {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  background: rgb(244, 244, 244);
  padding: 8px 15px;
}
.popup_t p {
  font-weight: 700;
}
.popup_c {
  padding: 8px 15px;
}
.popup_button {
  margin: 5px 0 0 0;
  width: 94%;
  height: 30px;
  padding: 0 10px;
  border: 2px solid #f4f4f4;
  border-radius: 3px;
}
.popup_b {
  margin: 10px 0 0 0;
  padding-left: 230px;
}
</style>

<style>
.newAt .vs-info-1 .el-input,
.newAt .vs-info-2 .el-input {
  /* margin: 10px 20px 0 10px; */
  margin-top: 10px;
  width: 160px;
}
.newAt .el-input__inner {
  height: 30px !important;
}
.newAt .el-input__icon {
  line-height: 30px !important;
}
.vs-info .barcode .el-switch {
  margin: 0 !important;
}

.newAt .enterBarcode .el-input {
  width: 486px;
  margin: 14px 17px;
}

.newAt .colorBox .el-input {
  width: 60px;
  margin-right: 10px;
}
.newAt .vs-info-1 .infoBox .el-input,
.newAt .vs-info-2 .infoBox .el-input {
  margin: 0 10px 0 0;
  width: 60px;
}
.newAt .vs-info-1 .infoBox .el-input--suffix,
.newAt .vs-info-2 .infoBox .el-input--suffix {
  width: 90px;
}
.newAt .colorBox .el-input--suffix {
  width: 90px;
}

/* 编辑表格样式 */
.newAt .tb-edit .el-input {
  display: none;
}
.newAt .tb-edit .activeCell .el-input {
  display: block;
}
.newAt .tb-edit .activeCell .el-input + span {
  display: none;
}
.newAt .tb-show .el-input {
  display: none;
}
.newAt .barcode .el-radio {
  padding-top: 5px;
}
</style>
